<script type="text/javascript">	
	$(document).ready(function(){ 
		$("#profile-saving").hide();
		$("#save").click(function(){
			$("#profile-saving").show();
			if(($('#newpword').val() == $('#newpword_con').val() && $('#newpword').val().length > 0 && $('#oldpword').val().length > 0 ) || ($('#newpword').val().length == 0 && $('#newpword_con').val().length == 0 && $('#oldpword').val().length == 0)){
				
				var totalText = $("input[name^=custom_text_pf_]").length;
				var totalTextbox = $("textarea[name^=custom_textbox_pf_]").length;
				var totalOptions = $("select[name^=custom_option_pf_]").length;
				//var totalRadio = $("input[type=radio][name^=custom_radio_pf_]").length;
				//var totalCheck = $("input[type=checkbox][name^=custom_checkbox_pf_]").length;
				
				var output = "";
				
				for(var i=1;i<=totalText;i++){
					current = $("input[name^=custom_text_pf_]:eq("+(i-1)+")");
					output += current.attr("alt") + ":sp:" + current.val() + ";";	
				}
				
				for(var i=1;i<=totalTextbox;i++){
					current = $("textarea[name^=custom_textbox_pf_]:eq("+(i-1)+")");
					output += current.attr("alt") + ":sp:" + current.val() + ";";	
				}
				
				for(var i=1;i<=totalOptions;i++){
					current = $("select[name^=custom_option_pf_]:eq("+(i-1)+") option:selected");
					output += current.attr("alt") + ":sp:" + current.val() + ";";	
				}
				
				/*
				for(var i=1;i<=totalRadio;i++){
					current = $("input[type=radio][name^=custom_radio_pf_]:nth-child("+i+"):selected");
					output += current.attr("alt") + ":sp:" + current.val() + ";";	
				}
				
				for(var i=1;i<=totalCheck;i++){
					current = $("input[type=checkbox][name^=custom_checkbox_pf_]:nth-child("+i+"):selected");
					output += current.attr("alt") + ":sp:" + current.val() + ";";	
				} */
				
				$.get('ajax/registration/save.php', {
														email: $('#email').val(),
														rname: $('#rname').val(),
														newpword: $('#newpword').val(),
														oldpword: $('#oldpword').val(),
														avatar: $('#avatar').val(),
														age: $('#age').val(),
														location: $('#location').val(),
														occupation: $('#occupation').val(),
														interests: $('#interests').val(),
														
														contact_msn: $('#contact_msn').val(),
														contact_icq: $('#contact_icq').val(),
														contact_jabber: $('#contact_jabber').val(),
														contact_gchat: $('#contact_gchat').val(),
														contact_yim: $('#contact_yim').val(),
														contact_website: $('#contact_website').val(),
														
														custom_links: output,
														
														signature: $('#sig').val()
														
													}, function(data){
														$("#profile-saving").hide();
														if(data == ""){
															alert("profile updated");
														} else {
															alert(data);
														}
														fetchPage('profile');	
													});
									  
				
			} else {
				$("#profile-saving").hide();
			}
			
		});
	});
</script>

<h2>{{profileTitle}}</h2>

<p>
<input name="custom_links" id="custom_links" type="hidden" value="" />
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="25%"><strong>Username</strong></td>
    <td width="25%">{{username}}</td>
    <td width="50%">&nbsp;</td>
  </tr>
  <tr>
    <td><strong>Email</strong></td>
    <td><input id="email" name="email" type="text" value="{{email}}" style="width:200px;" /></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td><strong>Your name</strong></td>
    <td><input id="rname" name="rname" type="text" value="{{rname}}" style="width:200px;" /></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td><strong>Your avatar url</strong></td>
    <td><input id="avatar" name="avatar" type="text" value="{{avatar}}" style="width:400px;" /></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td colspan="3" id="no_border">&nbsp;</td>
  </tr>
  <tr>
    <td><strong>Your age</strong></td>
    <td><input id="age" name="age" type="text" value="{{age}}" style="width:200px;" /></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td><strong>Your location</strong></td>
    <td><input id="location" name="location" type="text" value="{{location}}" style="width:400px;" /></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td><strong>Your occupation</strong></td>
    <td><input id="occupation" name="occupation" type="text" value="{{occupation}}" style="width:400px;" /></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td><strong>Your interests</strong></td>
    <td><input id="interests" name="interests" type="text" value="{{interests}}" style="width:400px;" /></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td colspan="3" id="no_border">&nbsp;</td>
  </tr>
  {{customfields}}
  <tr>
    <td colspan="3" id="no_border">&nbsp;</td>
  </tr>
  <tr>
    <td><strong>MSN</strong></td>
    <td><input id="contact_msn" name="contact_msn" type="text" value="{{contact_msn}}" style="width:400px;" /></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td><strong>ICQ</strong></td>
    <td><input id="contact_icq" name="contact_icq" type="text" value="{{contact_icq}}" style="width:400px;" /></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td><strong>Jabber</strong></td>
    <td><input id="contact_jabber" name="contact_jabber" type="text" value="{{contact_jabber}}" style="width:400px;" /></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td><strong>Google Chat</strong></td>
    <td><input id="contact_gchat" name="contact_gchat" type="text" value="{{contact_gchat}}" style="width:400px;" /></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td><strong>YIM</strong></td>
    <td><input id="contact_yim" name="contact_yim" type="text" value="{{contact_yim}}" style="width:400px;" /></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td><strong>Website</strong></td>
    <td><input id="contact_website" name="contact_website" type="text" value="{{contact_website}}" style="width:400px;" /></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td colspan="3" id="no_border">&nbsp;</td>
  </tr>
  <tr>
    <td><strong>Signature</strong></td>
    <td><textarea name="sig" id="sig" cols="" rows="5" style="width:400px;">{{signature}}</textarea></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td colspan="3" id="no_border">&nbsp;</td>
  </tr>
  <tr>
    <td>New password</td>
    <td><input id="newpword" name="newpword" type="password" style="width:200px;" /></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>Confirm New password</td>
    <td><input id="newpword_con" name="newpword_con" type="password" style="width:200px;" /></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>Current password</td>
    <td><input id="oldpword" name="oldpword" type="password" style="width:200px;" /></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td id="no_border">&nbsp;</td>
    <td id="no_border"><input id="save" name="save" type="button" value="save" style="float:left;" /><div id="profile-saving" class="loading-small"></td>
    <td id="no_border">&nbsp;</td>
  </tr>
</table>

</p>
